<template>
	<view class="Integral">
		<view class="header">
			
		</view>
		<!-- 积分余额 -->
		<view class="balance">
			<!-- 余额 -->
			<view class="Integral-balance">
				<view class="Integra-text">
					积分余额
				</view>
				<view class="Integra-balance">
					{{integrSum}}
				</view>
			</view>
			<!-- 说明、兑换 -->
			<view class="illustrate-exchange">
				<button class="btn illustrate" @click="gotoillustrate">积分说明</button>
				<button class="btn exchange">去兑换</button>
			</view>
		</view>
		<!-- 积分增加使用及清零切换选项卡 -->
		<view class="recording">
			<!-- 选项卡 -->
			<view class="btnbox">
				<button class="btn" :class="{isYbtn : isBtn ==1,isNbtn:isBtn ==0}" @click="zengFen">积分增加记录</button>
				<button class="btn btn-left " :class="{isNbtn : isBtn ==1, isYbtn:isBtn ==0}" @click="qingLing">使用及清零记录</button>
			</view>
			<!-- 记录 -->
			<view class="">
				<!-- 增加记录 -->
				<view class="zjLists" v-show="isZSelect">
					<view class="zjList-one" v-for="item in zjData" :key="item.id">
						<!-- 日期时间 -->
						<view class="dateTime">
							<view class="shu"></view>
							<view class="date">{{item.dateTime}}</view>
						</view>
						<!-- 积分 -->
						<view class="jifenNumber">
							<view class="jifenText">
								{{item.title}}
							</view>
							<view class="number">
								+{{item.number}}
							</view>
						</view>
					</view>
				</view>
				<!-- 清零记录 -->
				<view class="qlLists zjLists" v-show="isQSelect">
					<view class="zjList-one" v-for="item in qlData" :key="item.id">
						
						<!-- 积分 -->
						<view class="jifenNumber">
							<view class="jifenText">
								{{item.title}}
							</view>
							<view class="qlnumber">
								-{{item.number}}
							</view>
						</view>
						<!-- 日期时间 -->
						<view class="dateTime">
							<view class="date">{{item.dateTime}}</view>
						</view>
					</view>
					
				</view>
			</view>
		</view>
		<view class="footer">
			<image class="footerimg" src="https://wlsy.nanjingyunpeng.cn/weixin/image/footerImg.png"></image>
		</view>
	</view>
</template>

<script>
	import {
		userintegral
	} from "../../api/api.js"
	export default {
		data() {
			return {
			    isBtn:1,
				isZSelect:true,
				isQSelect:false,
				zjData:[],//增加积分
				qlData:[],//清零积分
				integrSum:0,//积分数
			}
		},
		onLoad(){
		this.userintegral(1)	
		},
		methods:{
			
			async userintegral(val){
				// console.log("val",val)
				let res = await userintegral({type:val})
				this.integrSum = res.data.userinfo.integral.substring(0,res.data.userinfo.integral.length-3)
				// console.log("积分",res)
				if(val == 1){
					if(res.code == 1000){
						this.zjData=[]
						res.data.userintegrallog.data.forEach((item,index)=>{
							this.zjData.push({
								title:item.title,
								number:item.change_num.substring(0,item.change_num.length-3),
								dateTime:item.created_at
							})
						})
					}
				}else{
					this.qlData=[]
					res.data.userintegrallog.data.forEach((item,index)=>{
						this.qlData.push({
							title:item.title,
							number:item.change_num.substring(0,item.change_num.length-3),
							dateTime:item.created_at
						})
					})
				}
				
			},
			zengFen(){
				this.isBtn=1
				this.isZSelect = true
				this.isQSelect = false
				this.userintegral(1)
			},
			qingLing(){
				this.isBtn=0
				this.isZSelect = false
				this.isQSelect = true
				this.userintegral(2)
			},
			//跳转积分说明
			gotoillustrate(){
				uni.navigateTo({
					url: '/pages/centerlist/illustrate'
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.Integral {
		min-width: 100%;
		min-height: 100%;
		background-color: #EEF7FE;
		padding: 30rpx;
		padding-top: 70rpx;
		box-sizing: border-box;
		.header{
			width: 750rpx;
			height: 40rpx;
			background:#466EE7 ;
			border-radius: 0rpx 0rpx 60rpx 60rpx;
			position: fixed;
			top: 0;
            left: 0;
			z-index: 999;
		}

		.balance {
			width: 690rpx;
			height: 228rpx;
			background: #FFFFFF;
			box-shadow: 0px 2rpx 8rpx 0px rgba(51, 51, 51, 0.05);
			border-radius: 30rpx 30rpx 30rpx 30rpx;
			opacity: 1;
			display: flex;
			padding: 50rpx 60rpx;
			box-sizing: border-box;
			justify-content: space-between;

			.Integra-text {
				font-size: 32rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 38rpx;

			}

			.Integra-balance {
				font-size: 60rpx;
				font-family: DIN-Bold, DIN;
				font-weight: bold;
				color: #CA1313;
				line-height: 70rpx;
				margin-top: 20rpx;
			}

			.illustrate-exchange {
				.btn {
					width: 172rpx;
					height: 60rpx;
					border-radius: 200rpx 200rpx 200rpx 200rpx;
					opacity: 1;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					line-height: 32rpx;
					line-height: 60rpx;
				}

				.illustrate {
					background: linear-gradient(1deg, #688EFA 0%, #466EE7 100%);
					color: #FFFFFF;
				}

				.exchange {
					border: 1px solid #688EFA;
					// border-image: linear-gradient(1deg, rgba(104, 142, 250, 1), rgba(70, 110, 231, 1)) 1 1;
					color: #4B73EA;
					margin-top: 20rpx;
				}
			}
		}
		.recording{
			margin-top:30rpx ;
			.btnbox{
				display: flex;
				.btn{
					display: inline-block;
					width: 173px;
					height: 48px;
					border-radius: 20rpx 0px 0px 20rpx;
					opacity: 1;
					font-size: 32rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					line-height: 90rpx;
				}
				.btn-left{
					border-radius: 0px 20rpx 20rpx 0px;
				}
				.isYbtn{
					background: linear-gradient(1deg, #688EFA 0%, #466EE7 100%);
					color: #FFFFFF;
				}
				.isNbtn{
					color: #333333;
					border: 1px solid #466EE7 ;
					background-color: #FFFFFF;
				}
			}
			
			
		}
		.zjLists{
			margin-top: 30rpx;
			z-index: 99;
			.zjList-one{
				width: 690rpx;
				height: 160rpx;
				background: #FFFFFF;
				box-shadow: 0px 2rpx 8rpx 0px rgba(51,51,51,0.05);
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				opacity: 1;
				margin-bottom: 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				padding: 30rpx;
				box-sizing: border-box;
				.dateTime{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					line-height: 32rpx;
					display: flex;
					width: 292rpx;
					justify-content: space-between;
					.shu{
						width: 4rpx;
						height: 24rpx;
						background: linear-gradient(1deg, #688EFA 0%, #466EE7 100%);
						border-radius: 200rpx 200rpx 200rpx 200rpx;
						opacity: 1;
						
					}
					
				}
				.jifenNumber{
					width: 100%;
					display: flex;
					justify-content: space-between;
					.jifenText{
						font-size: 32rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #333333;
						line-height: 38rpx;
					}
					.number{
						font-size: 32rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #4B73EA;
						line-height: 38rpx;
					}
					.qlnumber{
						color: #CA1313;
					}
				}
			}
		}
		
		.footer {
			width: 750rpx;
			height: 324rpx;
			position: fixed;
			bottom: 0;
			left: 0;
		
			.footerimg {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>
